//
//
//   时间：2022.11.21
//
//

const {ccclass, property} = cc._decorator;

@ccclass
export default class AutoScale extends cc.Component {
    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        cc.Canvas.instance.node.on(cc.Node.EventType.SIZE_CHANGED,this.onScale,this);
    }
    onScale(){
        let orWidth = cc.Canvas.instance.designResolution.width;
        let orHeight = cc.Canvas.instance.designResolution.height;
        let newWidth = cc.Canvas.instance.node.width;
        let newHeight = cc.Canvas.instance.node.height;
        let scale = newWidth/orWidth<newHeight/orHeight?newWidth/orWidth:newHeight/orHeight;
        this.node.scale = scale;
    }

    start () {
        this.onScale();
    }

    // update (dt) {}
}
